package cn.kgc.web;

import cn.kgc.entity.AirQualityIndex;
import cn.kgc.entity.District;
import cn.kgc.service.AirQualityIndexService;
import cn.kgc.service.DistrictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/air")
public class AirContorller {
    @Autowired
    private AirQualityIndexService airQualityIndexService;
    @Autowired
    private DistrictService districtService;

    @RequestMapping("/list")
    public String selectAir(Model model){
        List<AirQualityIndex> airlist = airQualityIndexService.airList();
        List<District> dislist = districtService.disAll();
        model.addAttribute("air",airlist);
        model.addAttribute("dis",dislist);
        return "select";
    }
    @RequestMapping("/find")
    @ResponseBody
    public List<AirQualityIndex> find(Integer id){
        return airQualityIndexService.find(id);
    }
    @RequestMapping("/toadd")
    public String toadd(Model model){
        List<AirQualityIndex> airlist = airQualityIndexService.airList();
        List<District> dislist = districtService.disAll();
        model.addAttribute("air",airlist);
        model.addAttribute("dis",dislist);
        return "add";
    }
    @PostMapping("/add")
    @ResponseBody
    public boolean add(@ModelAttribute AirQualityIndex air){
        return  airQualityIndexService.addAir(air);
    }
}
